package jjn.round1;

/**
 * @author Jjn
 * @since 2022/8/3 23:28
 */
public class LeetCode374_GuessNumber extends GuessGame {


    public LeetCode374_GuessNumber(Integer max, Integer picked) {
        super(max, picked);
    }

    public int guessNumber(int n) {
        int low = 0, high = n;
        while(low <= high) {
            int mid = low + (high - low) / 2;
            int result = guess(mid);
            if(result == 0) {
                return mid;
            }
            if(result > 0) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return -1;
    }
}
